%{
#include <stdio.h>
extern int yylex();
extern void yyerror();

static float reg[26];
%}

%token '\n' '+' '/' '*' '(' ')' '=' '$' PRINT
%token <intVal> NB LETTER
%token <floatVal> FLOAT
%type <floatVal> Expression List Dollar
%union {
  int intVal;
  float floatVal;
  char* string;
}
%left '+' '-'
%left '*' '/'
%right '='
%left UMINUS

%%
List:
    | List Instruction '\n'
    | List Print '\n'
    | List Expression  '\n' { $$=$2; printf("Valeur:%f ||\n",$2); }
    | error { yyerror("IGNORE\n");  yyerrok; yyclearin; }
    ;

Instruction: LETTER '=' Expression { reg[$1]=$3; }
           ;

Print: PRINT LETTER { printf("Print Valeur: %f ||\n",reg[$2]); }
     ;

Expression: Expression '*' Expression  { $$=$1*$3; /* printf("*= %f |\n",$$); */  }
          | Expression '+' Expression  { $$=$1+$3; /* printf("+= %f |\n",$$); */ }
          | Expression '-' Expression  { $$=$1-$3; /* printf("-= %f |\n",$$); */ }
          | Expression '/' Expression  { $$=$1/$3; /* printf("/= %f |\n",$$); */ }
          | '(' Expression ')' { $$=$2; }
          | FLOAT { $$=$1; /* printf("Test NB = %f",$1); */  }
          | Dollar { $$=$1; }
          | '-' Expression %prec UMINUS { $$=-$2; }
          ;

Dollar: '$' LETTER { $$ = reg[$2]; }
      ;

%%
